package kr.co.dongpang.android;



import java.util.ArrayList;
import java.util.HashMap;

import kr.co.dongpang.android.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;

public class ImageListFragment extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        
        setContentView(R.layout.fragment_imagelist);

        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String,String>>();
        JSONObject json = JSONfunctions.getJSONfromURL("http://dongpang.co.kr/android/admin.v02/json.php");
      
        try {
        	JSONArray earthquakes = json.getJSONArray("earthquakes");

        	for (int i = 0; i < earthquakes.length(); i++) { 
        		HashMap<String, String> map = new HashMap<String, String>();
        		JSONObject jobject = earthquakes.getJSONObject(i);

        		map.put("goodcd", jobject.getString("goodcd"));
        		mylist.add(map);
        		
        		Log.d("","goodnm:"+jobject.getString("goodnm"));
        		
        		
        	}
    	} catch (JSONException e) {
        	Log.e("log_tag","Error Parsing data" + e.toString());
    	}
        

        setListAdapter(new ImageListFragmentAdapter(mylist));
        
        ImageDownloader.Mode mode = ImageDownloader.Mode.NO_ASYNC_TASK;
        mode = ImageDownloader.Mode.CORRECT;
        ((ImageListFragmentAdapter) getListAdapter()).getImageDownloader().setMode(mode);
    }

}

